﻿using System.Diagnostics;

namespace LFSRecord2.Model.UserActions
{
    public class UserActionPropertyBindingChanged : UserActionBase
    {
        // Action description, so we can replay this action (and reverse it)
        public int LayerIndex { get; set; }
        public int PropertyIndex { get; set; }
        public LayerPropIndex oldBinding { get; set; }
        public LayerPropIndex newBinding { get; set; }

        public UserActionPropertyBindingChanged()
        {
            Action = UserActionTypes.PropertyBindingChanged;
        }

        public override void DoUndo()
        {
            Debug.WriteLine("Undoing a PropertyBindingChanged action");
            if (oldBinding.LayerIndex == -1 || oldBinding.PropertyIndex == -1)
                LfsRecordController.project.Layers[LayerIndex].Properties[PropertyIndex].BoundProperty = null;
            else
                LfsRecordController.project.Layers[LayerIndex].Properties[PropertyIndex].BoundProperty = LfsRecordController.project.GetProperty(oldBinding);
            LfsRecordController.project.Layers[LayerIndex].UpdatedCurrentValues = CompLayerPropertyUpdateTypes.All;
        }

        public override void DoRedo()
        {
            Debug.WriteLine("Redoing a PropertyBindingChanged action");
            if (newBinding.LayerIndex == -1 || newBinding.PropertyIndex == -1)
                LfsRecordController.project.Layers[LayerIndex].Properties[PropertyIndex].BoundProperty = null;
            else
                LfsRecordController.project.Layers[LayerIndex].Properties[PropertyIndex].BoundProperty = LfsRecordController.project.GetProperty(newBinding);
            LfsRecordController.project.Layers[LayerIndex].UpdatedCurrentValues = CompLayerPropertyUpdateTypes.All;
        }
    }
}
